from aiogram_dialog import Dialog, Window
from aiogram_dialog.widgets.kbd import Cancel, ScrollingGroup, Select

from src.bot.dialogs.getters.calendars import user_calendars_getter
from src.bot.dialogs.widgets import FormatWithLang, LocaleText
from src.bot.states.user import UserCalendarsSG

from .handlers import select_calendar

select_calendar_window = Window(
    LocaleText("select-calendar-msg"),
    ScrollingGroup(
        Select(
            FormatWithLang("{item.title}", "title"),
            "calendars_sel",
            lambda calendar: calendar.id,
            "user_calendars",
            on_click=select_calendar,
        ),
        width=1,
        height=4,
        id="calendarssel",
        hide_on_single_page=True,
    ),
    Cancel(LocaleText("back-btn")),
    state=UserCalendarsSG.calendars_list,
    getter=user_calendars_getter,
)


user_calendars_dialog = Dialog(select_calendar_window)
